
<link rel="stylesheet" type="text/css" href="product/css/screen.css" />
<script type="text/javascript" src="product/js/jquery-1.3.2.js" ></script>
<script type="text/javascript" src="product/js/ajaxupload.3.5.js" ></script>
<script type="text/javascript" >
	$(function(){
		var btnUpload=$('#upload');
		var status=$('#status');
		new AjaxUpload(btnUpload, {
			action: '../controller/product/upload-file.php',
			name: 'uploadfile',
                        dataType: 'json',
			data: '',  
                        onComplete: function(file,data)      //on recieve of reply
			  {
				var id = data; 
                                $('<li></li>').appendTo('#files').html('<img src="../images-products/thumbnail/'+id+'" alt="" /><br />'+id+'<input id="file" type="checkbox" name="file" value="'+id+'" onClick="visibleButton()"><br/>'); 
			  }                             							
		});
	});
        function visibleButton() {
		var buttonToShow = document.getElementById("invisiButton");
		buttonToShow.style.visibility = "visible";
	}
        $().ready(function() { 
            $('#invisiButton').click(function(){ 
                            var selected = new Array();

                                    $("input:checkbox[name=file]:checked").each(function() {
                                            selected.push($(this).val());
                                    });

                                    $.ajax({
                                            type: "POST",
                                            url: "../controller/product/delete.php",
                                            data: "file=" + selected,
                                            success: function(){

                                                    $('input:checkbox[name=file]:checked').parent().remove();

                                                    $('div#mainbody').fadeIn();
                                            }
                                    });
                            return false;

            }); 
            
            $('#save').click(function(){ 

                            var selected = new Array();
                            

                                    $("input:checkbox[name=file]").each(function() {
                                            selected.push($(this).val());
                                    });
                            var selectedname = '';
                            for(var i=0;i<selected.length;i++)
                            {
                                selectedname += selected[i]+",";
                            }
                                    var pro_desc = FCKeditorAPI.GetInstance('contents').GetHTML('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
                                    var pro_name = form1.pro_name.value;
                                    var pro_prince = form1.pro_prince.value;
                                    var pro_cate = form1.categories.value;
                    
                                    $.ajax({
                                            type: "POST",
                                            url: "../controller/product/insert_pro.php",
                                            data: {selectedname:selectedname,pro_desc:pro_desc,pro_name:pro_name,pro_prince:pro_prince,pro_cate:pro_cate},
                                            success: function(){
												alert("Insert success");  
												window.location.replace('index.php');
                                            }
                                    });
                            return false;

            }); 
        }); 
</script>


<?php
  require_once '../model/global.inc.php';  
  include('fckeditor/fckeditor.php') ;
?>

          
            <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" >
                <table width="780px" cellpadding="0" cellspacing="0">
                    <tr>
                        <td colspan="3" valign="top">
                            <div class="titleAdmin">
                                Insert product
                            </div>
                        </td>
                    </tr>
                    <tr><td><p><br></p></td></tr>
                    <tr>
                        <td width="180px" class="textAdmin">
                            Product name:
                        </td>
                        <td clospan="2" valign="top">
                            <input name="pro_name" type="text" id="pro_name" size="30" class="in"/>
                        </td>                       
                    </tr>
                    <tr>
                        <td class="textAdmin">
                            Categories:
                        </td>
                        <td clospan="2" valign="top">
                            <select name="categories" id="categories">
                                <option value="" selected>- categories -</option>
                                    <?php

                                            $result = mysql_query("SELECT * FROM tblcategories");

                                            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
                                                    <option value="<?php echo $row["categories_name"] ?>"><?php echo $row["categories_name"] . '<br />'; ?></option>
                                            <?php 
                                            }
                                            ?>
                                 
                                </select>
                        </td>                       
                    </tr>
                    <tr>
                        <td valign="top" colspan="3" class="textAdmin">
                            Product description:
                        </td>
                     </tr>
                     <tr>
                        <td colspan="3" >
                            <?php
                               
                                $ctrl_name = 'product_long_desc';
                                $sBasePath = 'product/fckeditor/';
                                $oFCKeditor = new FCKeditor('contents') ;
                                $oFCKeditor->Height = "500px";
                                $oFCKeditor->Width = "770px";
                                $oFCKeditor->BasePath = $sBasePath ;
                                $oFCKeditor->Value = "" ;
                                $oFCKeditor->Create() ;
                            ?>
                           
                        </td>
                    </tr>
                    <tr>
                        <td valign="top" class="textAdmin">
                            Product price:
                        </td>
                        <td clospan="2">
                            <input name="pro_prince" type="text" id="pro_prince" size="30" class="in"/>
                        </td>                       
                    </tr>
                    <tr>
                        <td valign="top" class="textAdmin">
                            Product images:
                        </td>
                        <td class="textAdmin">
                            <div id="mainbody" >
                                <div id="upload" ><span>Upload File</span></div><span id="status" ></span>
		
                                <ul id="files" ></ul>
                                <input type="submit" id="invisiButton" value="Delete" style="visibility:hidden;" />
                            </div>
                        </td>                    
                    </tr>
                     <tr>                       
                        <td colspan="2" class="textAdmin">
                             <input type="submit" value="Save" name="submit" id="save"/>
                        </td>                    
                    </tr>
                </table>
              
              
          </form>
